package dao.impl;

import java.sql.ResultSet;

import dao.BaseDao;
import dao.Mapper;
import dao.UserDao;
import entity.User;

public class UserDaoImpl extends BaseDao implements UserDao {

	@Override
	public User findByName(String username) {
		String sql = "select * from sys_user where uname = ?";
		Mapper<User> mapper = new Mapper<User>() {

			@Override
			public User doMapper(ResultSet rs) throws Exception {
				User u = new User();
				u.setId(rs.getInt("uid"));
				u.setPassword(rs.getString("upassword"));
				u.setUsername(rs.getString("uname"));
				return u;
			}
		};
		return queryOne(sql, mapper, username);
	}

	@Override
	public int saveUser(User user) {
		String sql="insert into sys_user (uname,upassword) values (?,?)";
		return update(sql, user.getUsername(),user.getPassword());
	}

}
